home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-02 | 2.9 KB | 136 lines | [TEXT/ALFA] |
-
- ################################################################################
- # Shell routines.
- ################################################################################
-
-
- proc setShellMode {} {
- setTclMode
- changeMode "Csh"
- }
-
- proc initShell {} {
- insertText "Welcome to Alpha's Tcl shell."
- shellPrompt [lindex [winNames] 0]
- }
-
- # Output the prompt. We want the window name because some of the commands
- # we evaluate (such as 'edit') open a new window, and we want the insertion
- # to be done in the shell window.
- proc shellPrompt {winName} {
- regexp "(\[^:\]*):$" [pwd] crDum crDir
- insertText -w $winName "\r" $crDir "> "
- }
-
-
- # Called at all carriage returns.
- proc carriageReturn {} {
- global mode
- global indentOnCR
- set indentString ""
- deleteText [getPos] [selEnd]
- if {$indentOnCR} {
- set pos [getPos]
- set text [getText [lineStart $pos] $pos]
- for {set i 0; set len [string length $text]} {$i <= $len} {incr i} {
- set c [string index $text $i]
- if {($c != "\t") && ($c != "\ ")} {
- set indentString [string range $text 0 [expr $i-1]]
- break
- }
- }
- }
- insertText "\r" $indentString
- }
-
-
- proc tclCarriageReturn {} {
- global mode
- global _text
- global _returnText
- set pos [getPos]
- set ind [string first ">" [getText [lineStart $pos] $pos]]
- if {$ind < 0} {
- carriageReturn
- return
- }
- set lStart [expr [lineStart $pos]+$ind+2]
- endOfLine
- set _text [getText $lStart [getPos]]
- set fileName [lindex [winNames] 0]
- if {[getPos] != [maxPos]} {
- goto [maxPos]
- insertText -w $fileName $_text
- }
- if {[string first "mpw" $fileName] != -1} {
- set _returnText [dosc -n ToolServer -s $_text]
- insertText "\r" $_returnText
- mpwPrompt
- } else {
- uplevel #0 {catch $_text _returnText}
- if {[string length $_returnText]} {
- insertText -w $fileName "\r" $_returnText
- }
- shellPrompt $fileName
- }
- unset _text
- unset _returnText
- }
- bind '\r' carriageReturn
- bind '\r' tclCarriageReturn "Csh"
- bind '\r' tclCarriageReturn "MPW"
-
- proc startMPW {} {
- insertText "Welcome to Alpha's MPW shell (using ToolServer via AppleEvents)."
- launch "External1:TS/SS files:ToolServer"
- bind '\r' tclCarriageReturn "MPW"
- carriageReturn
- mpwPrompt
- }
- proc mpwPrompt {} {
- insertText "mpw> "
- }
-
- proc setMPWMode {} {
- changeMode "MPW"
- }
-
- # tclCarriageReturn
-
-
-
- #=============================================================================
- # Shell Aliases
- #=============================================================================
- proc l {args} {
- eval [concat "ls -F" $args]}
-
- proc ll {args} {
- eval [concat "ls -l" $args]}
-
-
- proc grep {pat args} {
- insertText "\r"
- set pat *$pat*
- set args [glob -nocomplain $args]
- foreach file $args {
- set id [open $file]
- while {[gets $id string] != "-1"} {
- if {[string match $pat $string] == 1} {
- insertText $file: $string "\r"
- }
- }
- close $id
- }
- }
-
-
- proc ts script {
- return [dosc -n ToolServer -s $script]
- }
-
- proc tl {} {
- launch "External:Babel:Tools:ToolServer"
- }
-
-